package com.docker.chy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.docker.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.chy.domain.DeptTji;
import com.docker.chy.service.IDeptTjiService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 部门消费统计Controller
 * 
 * @author fy
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/chy/bumen")
public class DeptTjiController extends BaseController
{
    @Autowired
    private IDeptTjiService deptTjiService;

    /**
     * 查询部门消费统计列表
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptTji deptTji)
    {
        startPage();
        List<DeptTji> list = deptTjiService.selectDeptTjiList(deptTji);
        return getDataTable(list);
    }

    /**
     * 导出部门消费统计列表
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:export')")
    @Log(title = "部门消费统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeptTji deptTji)
    {
        List<DeptTji> list = deptTjiService.selectDeptTjiList(deptTji);
        ExcelUtil<DeptTji> util = new ExcelUtil<DeptTji>(DeptTji.class);
        util.exportExcel(response, list, "部门消费统计数据");
    }

    /**
     * 获取部门消费统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(deptTjiService.selectDeptTjiByDeptId(deptId));
    }

    /**
     * 新增部门消费统计
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:add')")
    @Log(title = "部门消费统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptTji deptTji)
    {
        return toAjax(deptTjiService.insertDeptTji(deptTji));
    }

    /**
     * 修改部门消费统计
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:edit')")
    @Log(title = "部门消费统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptTji deptTji)
    {
        return toAjax(deptTjiService.updateDeptTji(deptTji));
    }

    /**
     * 删除部门消费统计
     */
    @PreAuthorize("@ss.hasPermi('chy:bumen:remove')")
    @Log(title = "部门消费统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(deptTjiService.deleteDeptTjiByDeptIds(deptIds));
    }

    //查询不同部门的接诊次数和总金额
    @Anonymous
    @GetMapping("/selectDeptTjiListMoney")
    public AjaxResult selectDeptTjiListMoney()
    {
        List<DeptTji> result = deptTjiService.selectDeptTjiListMoney();
        return AjaxResult.success(result);
    }

}
